package com.fourth.service.impl;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fourth.dao.UBuserInfoDao;
import com.fourth.dao.UBbusinessInfoDao;
import com.fourth.service.UBuserInfoService;
import com.ljx.entity.BusinessInfo;
import com.ljx.entity.UserInfo;
import com.ljx.security.util.WebUtils;
import com.ljx.utils.JwtUtil;
import com.ljx.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author C-Q
 * @version 1.1.0
 * @Description: 用户信息
 * @date 2023/3/2
 */
@Service
public class UBuserInfoServiceImpl implements UBuserInfoService {

    @Autowired(required = false)
    private UBuserInfoDao ubUserInfoDao;

    @Autowired(required = false)
    private UBbusinessInfoDao uBbusinessInfoDao;

    /**
     * 根据当前登录用户名查询当前用户信息
     * @return
     */
    @Override
    public Result UserOrBusinessInfo() {

        //得到token
        String token = WebUtils.getRequest().getHeader("token");
        //解析token
        Map<String, Object> map = JwtUtil.getTokenChaim(token);
        //拿到token中携带的用户名
        String username = (String) map.get("username");
        String loginType = (String) map.get("loginType");
        //打印拿到数据的商户类型
        System.out.println(loginType+"!!!!~~~~");

        //判断当前拿到的token数据为哪个的客户
        if("USER_PHONE".equals(loginType)){
            //把拿到的token数据和数据库进行对比和存储
            QueryWrapper<UserInfo> wrapper = new QueryWrapper<>();
            wrapper.eq("telephone",username);
            UserInfo userInfo = ubUserInfoDao.selectOne(wrapper);
            return new Result(2000,"查询用户信息成功",userInfo);
        }

        QueryWrapper<BusinessInfo> wrapper = new QueryWrapper<>();
        BusinessInfo businessInfo = uBbusinessInfoDao.selectByTelephone(username);
        return new Result(2000,"查询商户信息成功",businessInfo);


    }




    //根据当前用户id修改用户的信息

    @Override
    public Result UserRevise(UserInfo userInfo) {
        int update = ubUserInfoDao.updateById(userInfo);
        return new Result(2000,"用户信息修改成功",update);

    }




}
